package io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.visitor;

import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.BooleanElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.IntegerElement;
import io.gitee.yth.design.pattern.test.core.pattern.behavioral.visitor.element.StringElement;

/**
 * @author yth
 * @since 2023-04-29-16:41
 */
public class ByteLengthVisitor implements Visitor {

    /**
     * 累计状态（字节数）
     */
    private int length = 0;

    @Override
    public void visitInteger(IntegerElement e) {
        length += 4;
    }

    @Override
    public void visitBoolean(BooleanElement e) {
        length += 1;
    }

    @Override
    public void visitString(StringElement e) {
        length += e.getValue().length() << 1;
    }

    public int getLength() {
        return length;
    }
}
